#include<bits/stdc++.h>
using namespace std;
int t, n, m, L, vmax;
int l[3005], r[3005], vis1[1000005], d[3005], v[3005], a[3005], p[3005], s, sum, ans1, ans2, len[3005][3005], w[3005], vis2[3005];
double disl(int x){
    return abs(vmax * vmax - v[x] * v[x]) / 2 / abs(a[x]);
}
int main(){
    ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
    freopen("detect.in", "r", stdin);
    freopen("detect.out", "w", stdout);
    cin >> t;
    while (t --){
        s = 0; sum = 0; ans1 = 0; ans2 = 0;
        memset(vis1, 0, sizeof(vis1));
        memset(vis2, 0, sizeof(vis2));
        memset(d, 0, sizeof(d));
        memset(v, 0, sizeof(v));
        memset(a, 0, sizeof(a));
        memset(p, 0, sizeof(p));
        memset(l, 0, sizeof(l));
        memset(r, 0, sizeof(r));
        memset(len, 0, sizeof(len));
        memset(w, 0, sizeof(w));
        cin >> n >> m >> L >> vmax;
        for (int i = 1; i <= n; i ++)
            cin >> d[i] >> v[i] >> a[i];
        for (int i = 1; i <= m; i ++){
            cin >> p[i];
            vis1[p[i]] = 1;
        }
        for (int i = 1; i <= L; i ++)
            vis1[i] += vis1[i - 1];
        for (int i = 1; i <= n; i++){
            int lx, rx;
            if (a[i] <= 0 && v[i] <= vmax) continue;
            lx = d[i]; rx = L + 1;
            if(a[i] > 0 && v[i] <= vmax) lx += int(disl(i)) + 1;
            if(a[i] < 0) rx = min(rx, disl(i) == int(disl(i)) ? d[i] + int(disl(i)) : d[i] + int(disl(i)) + 1);
            if(lx > L) continue;
            if(vis1[rx - 1] - vis1[lx - 1]) ans1 ++;
            l[i] = vis1[lx - 1] + 1;
            r[i] = vis1[rx - 1];
            for(int j = l[i]; j <= r[i]; j ++){
                w[j] ++;
                len[j][i] = 1;
            }
        }
        int maxa = 0, maxb = 0;
        for (int i = 1; i <= m; i ++){
            maxa = maxb = 0;
            for(int j = 1; j <= m; j ++)
                if(w[j] > maxa){
                    maxa = w[j];
                    maxb = j;
                }
            if (!maxb) break;
            w[maxb] = 0;
            ans2 ++;
            for(int j = 1; j <= n; j ++){
                if(len[maxb][j] && vis2[j] == 0){
                    for(int k = l[j]; k <= r[j]; k ++){
                        w[k] --;
                    }
                    vis2[j] = 1;
                }
            }
        }
        cout << ans1 << " " << m - ans2 << endl;
    }
    return 0;
}
